package com.goldmantis.alitrip.controller;

import com.goldmantis.alitrip.service.FlightCityService;
import com.goldmantis.alitrip.service.TrainCityService;
import com.taobao.api.response.AlitripBtripFlightCitySuggestResponse;
import com.taobao.api.response.AlitripBtripTrainCitySuggestResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @Author:Shmily
 * @Description:
 * @Date:Create in 14:24 2018/1/15
 */
@Controller
@CrossOrigin(value = "*",maxAge = 3600)
@RequestMapping("train/city/")
public class TrainCityController {

    @Autowired
    private TrainCityService trainCityService;

    /**
     * 火车票城市建议
     * @param cityName
     * @param userId
     * @return
     */
    @RequestMapping(value = "suggest",method = RequestMethod.GET)
    public ResponseEntity<AlitripBtripTrainCitySuggestResponse> suggest(@RequestParam("cityName") String cityName, @RequestParam("userId") String userId) {
        try {
            cityName=new String(cityName.getBytes("ISO-8859-1"),"UTF-8");
            AlitripBtripTrainCitySuggestResponse rsp = trainCityService.getTrainCitySuggest(cityName,userId);
            return ResponseEntity.ok(rsp);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

}
